import unittest
from time import sleep
import requests
from api.api_dlce import RegLoginApi
from common.read_json import read_json
from common.封装数据库操作方法 import clear_user_info
from common.断言参数化 import common_assert, com_assert
from parameterized import parameterized

class TestRegLogin(unittest.TestCase):
    def setUp(self) -> None:
        clear_user_info()
        self.session = requests.session()
        self.api = RegLoginApi(self.session)

    def tearDown(self) -> None:
        self.session.close()
        # clear_user_info()

    @parameterized.expand(read_json('test_login','img_verify_code'))
    # 获取图片验证码测试用例
    def test01_img_verify_code(self,r,status_code):
        resp = self.api.get_img_verify_code(r)
        com_assert(self, resp, status_code)

    @parameterized.expand(read_json('test_login', 'phone_verify_code'))
    # 获取短信验证码测试用例
    def test02_phone_verify_code(self,phone,img_verify_code,status_code,status,description):
        self.api.get_img_verify_code(123)
        resp = self.api.get_phone_verify_code(phone, img_verify_code, 'reg')
        common_assert(self,resp,status_code,status,description)

    @parameterized.expand(read_json('test_login', 'user_register'))
    # 注册测试用例
    def test03_register(self,phone,img_verify_code,status_code,status,description,phone_code,password,dy_server,invite_phone):
        self.api.get_img_verify_code(123)
        self.api.get_phone_verify_code(phone, img_verify_code, 'reg')
        resp = self.api.user_register(phone, password, img_verify_code, phone_code, dy_server, invite_phone)
        common_assert(self, resp, status_code, status, description)

    @parameterized.expand(read_json('test_login', 'user_login'))
    # 登录测试用例
    def test04_user_login(self,keywords,password,status_code,status,description):
        resp=self.api.user_login(keywords,password)
        common_assert(self,resp,status_code,status,description)

    @unittest.skip
    # @parameterized.expand(read_json('test_login', 'query_user_login'))
    def test05_user_login_pwd_error(self,keywords,password,status_code,status,description):
        resp1 = self.api.user_login(keywords, password)
        common_assert(self, resp1, status_code, status, description)
        resp2 = self.api.user_login(keywords, password)
        common_assert(self, resp2, status_code, status, description)
        resp3 = self.api.user_login(keywords, password)
        common_assert(self, resp3, status_code, status, description)
        sleep(60)
        resp4 = self.api.user_login(keywords, password)
        common_assert(self, resp4, status_code, status, description)


































